﻿#define _CRT_SECURE_NO_WARNINGS 1
#include"game.h"
//初始化棋盘
void initboard(char board[rows][cols], int ROWS, int COLS, char set)
{
	int i =0 ;
	for (i = 0; i < rows; i++)
	{
		int j = 0;
		for (j = 0; j < cols; j++)
		{
			board[i][j] = set;
		}
	}
}
void displayboard(char board[rows][cols], int ROW, int COL)
{
	printf("---扫雷游戏---\n");
	int i = 0;
	for (i = 0; i <= row; i++)
	{
		printf("%d ", i);
	}
	printf("\n");
	for (i = 1; i <=row; i++)
	{
		int j = 1;
		printf("%d ", i);
		for (j = 1; j <= col; j++)
		{
			printf("%c ", board[i][j]);
		}
		printf("\n");
	}
}
void setmine(char board[rows][cols], int ROW, int COL)
{
	int count = EASY_COUNT;
	while (count)
	{
		int i = rand() % row+1;
		int y = rand() % col+1;
		if (board[i][y] == '0')
		{
			board[i][y] = '1';
			count--;
		}
	}
}
int GETMINECOUNT(char mine[rows][cols], int x, int y)
{
	return (mine[x - 1][y - 1] + mine[x - 1][y] + mine[x - 1][y + 1] + mine[x][y - 1] + mine[x][y + 1] + mine[x + 1][y - 1] + mine[x + 1][y] + mine[x + 1][y + 1] - 8 * '0');
		
		
}
void findmine(char mine[rows][cols], char show[rows][cols], int ROW, int COL)
{
	int x = 0;
	int y = 0;
	int win = 0;
	while (win < row * col - EASY_COUNT)
	{
		printf("一共有10个雷\n");
		printf("请输入要排查的坐标\n");
		scanf("%d %d", &x, &y);
		if (x > 0 && x <= row && y > 0 && y <= col)
		{
			if (mine[x][y] == '1')
			{
				printf("很遗憾，你被炸死了\n雷盘长这样");
				displayboard(mine, row, col);
				break;
			}
			else
			{
				int count = GETMINECOUNT(mine, x, y);
				show[x][y] = count + '0';
				displayboard(show, row, col);
				win++;
			}
		}
		else
		{
			printf("非法输入，请重新输入\n");
		}
	}
	if (win == row * col - EASY_COUNT)
	{
		printf("恭喜你，排雷成功！！\n");
		displayboard(mine, row, col);
	}
}